export class Singleton {
    private static _instances: Map<Function, any> = new Map();
    public static getInstance<T extends Singleton>(this: new () => T): T {
        if (!Singleton._instances.has(this)) {
            Singleton._instances.set(this, new this());
        }
        return Singleton._instances.get(this);
    }

    public constructor() {
        const cls = this.constructor as typeof Singleton;
        if (Singleton._instances.has(cls)) {
            throw new Error("Singleton class can't be instantiated more than once.");
        }
    }
}